package com.zhongshengnetwork.rightbe.game.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupWindow;

import com.bumptech.glide.Glide;
import com.dd.CircularProgressButton;
import com.zhongshengnetwork.rightbe.MainActivity;
import com.zhongshengnetwork.rightbe.R;
import com.zhongshengnetwork.rightbe.common.AppThemeUtils;
import com.zhongshengnetwork.rightbe.common.CommonUtils;
import com.zhongshengnetwork.rightbe.common.GsonTools;
import com.zhongshengnetwork.rightbe.common.dialog.PayDialog;
import com.zhongshengnetwork.rightbe.common.utils.ToastUtil;
import com.zhongshengnetwork.rightbe.game.activity.GameRangeActivity;
import com.zhongshengnetwork.rightbe.game.activity.PKMenuActivity;
import com.zhongshengnetwork.rightbe.game.activity.PrePKActivity;
import com.zhongshengnetwork.rightbe.gsonmodel.PKMenuModel;
import com.zhongshengnetwork.rightbe.gsonmodel.PKShareModel;
import com.zhongshengnetwork.rightbe.gsonmodel.PKUserModel;

import android.view.View.OnClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by luojingxing on 2018/4/14.
 */

public class PKMenuPopWindow extends PopupWindow{
    private Activity mainActivity;
    private View mMenuView;
    private CircularProgressButton pk_menu_pop_title;
    private ImageView pk_menu_pop_startpk;
    private ImageView pk_menu_pop_middlepk;
    private ImageView pk_menu_pop_highpk;
    private ImageView pk_menu_pop_facepk;
    private ImageView pk_menu_pop_rangepk;
    private ImageView pk_menu_pop_close;
    private ImageView getgold;

    public List<PKMenuModel> pkMenuList = new ArrayList<>();
    public PKShareModel pkShareModel;
    public PKUserModel pkUserModel;
    public String code = "";
    public PKMenuModel mPKMenuModel;

    public void showMenu(String data){
        pkShareModel = GsonTools.getPKShareModel(data);
        pkUserModel = GsonTools.getPKUserModel(data);
        List<PKMenuModel> list = GsonTools.getPKMenuModel(data);
        if (list != null && list.size() > 0) {
            pkMenuList.clear();
            pkMenuList.addAll(list);
        }
        mainActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                for(int i = 0; i < pkMenuList.size(); i++){
                    PKMenuModel model = pkMenuList.get(i);
                    if (i == 0){
                        Glide.with(mainActivity).load(model.getColor()).placeholder(AppThemeUtils.getInstance().getDefaultImageBg()).dontAnimate().into(pk_menu_pop_startpk);
                    }else if (i == 1){
                        Glide.with(mainActivity).load(model.getColor()).placeholder(AppThemeUtils.getInstance().getDefaultImageBg()).dontAnimate().into(pk_menu_pop_middlepk);
                    }else if (i == 2){
                        Glide.with(mainActivity).load(model.getColor()).placeholder(AppThemeUtils.getInstance().getDefaultImageBg()).dontAnimate().into(pk_menu_pop_highpk);
                    }else if (i == 3){
                        Glide.with(mainActivity).load(model.getColor()).placeholder(AppThemeUtils.getInstance().getDefaultImageBg()).dontAnimate().into(pk_menu_pop_facepk);
                    }else if (i == 4){
                        Glide.with(mainActivity).load(model.getColor()).placeholder(AppThemeUtils.getInstance().getDefaultImageBg()).dontAnimate().into(pk_menu_pop_rangepk);
                    }
                }
            }
        });
    }

    public PKMenuPopWindow(Activity context, OnClickListener itemsOnClick){
        super(context);
        mainActivity = context;
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(R.layout.pkmenu_pop_menu, null);
        pk_menu_pop_title = (CircularProgressButton) mMenuView.findViewById(R.id.pk_menu_pop_title);
        pk_menu_pop_title.setBackgroundColor(Color.parseColor("#5591cd"));
        pk_menu_pop_title.setStrokeColor(Color.parseColor("#5591cd"));
        pk_menu_pop_title.setText("王者对战");
        pk_menu_pop_startpk = (ImageView) mMenuView.findViewById(R.id.pk_menu_pop_startpk);
        pk_menu_pop_middlepk = (ImageView) mMenuView.findViewById(R.id.pk_menu_pop_middlepk);
        pk_menu_pop_highpk = (ImageView) mMenuView.findViewById(R.id.pk_menu_pop_highpk);
        pk_menu_pop_facepk = (ImageView) mMenuView.findViewById(R.id.pk_menu_pop_facepk);
        pk_menu_pop_rangepk = (ImageView) mMenuView.findViewById(R.id.pk_menu_pop_rangepk);

        pk_menu_pop_close = (ImageView) mMenuView.findViewById(R.id.pk_menu_pop_close);
        getgold = (ImageView) mMenuView.findViewById(R.id.getgold);

        //设置按钮监听
        pk_menu_pop_startpk.setOnClickListener(itemsOnClick);
        pk_menu_pop_middlepk.setOnClickListener(itemsOnClick);
        pk_menu_pop_highpk.setOnClickListener(itemsOnClick);
        pk_menu_pop_facepk.setOnClickListener(itemsOnClick);
        pk_menu_pop_rangepk.setOnClickListener(itemsOnClick);
        pk_menu_pop_close.setOnClickListener(itemsOnClick);
        getgold.setOnClickListener(itemsOnClick);

        //设置SelectPicPopupWindow的View
        this.setContentView(mMenuView);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.AnimBottom);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xe0f0f0f0);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
    }

}
